'use strict';

var _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');
Object.defineProperty(exports, '__esModule', {
  value: true,
});
exports.default = void 0;
var _slicedToArray2 = _interopRequireDefault(require('@babel/runtime/helpers/slicedToArray'));
var _react = require('react');
var _default = function _default(options) {
  var _useState = (0, _react.useState)(Array.isArray(options) ? options : []),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    innerOptions = _useState2[0],
    setInnerOptions = _useState2[1];
  var fetchOptions = (0, _react.useCallback)(
    function (params) {
      if (typeof options === 'function') {
        return options(params).then(function (data) {
          setInnerOptions(data);
        });
      }
    },
    [options],
  );
  (0, _react.useEffect)(
    function () {
      if (typeof options === 'function') {
        fetchOptions();
      } else if (Array.isArray(options)) {
        setInnerOptions(options);
      }
    },
    [options],
  );
  return {
    options: innerOptions,
    setOptions: setInnerOptions,
    fetchOptions: fetchOptions,
  };
};
exports.default = _default;
